<?php

declare(strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use \think\facade\Db;
use think\facade\Cache;

class gencode extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('app\command\gencode')
            ->setDescription('the app\command\gencode command');
    }

    protected function execute(Input $input, Output $output)
    {
        $thisyears = Db::query("select * from admin_budget where type = 1 limit 1000");
        $lastyears = Db::query("select * from admin_budget where type = 2 limit 1000");

        $lists = Db::query("select * from admin_budget limit 1000");

        $arr = [];

        foreach ($lists as $row) {
            $key = $row['functional_category_code_class'] . $row['functional_category_code_fund'] . $row['functional_category_code_item'];
            $title = $row['functional_category_name_class'] . '（类）' . $row['functional_category_name_fund'] . '（款）' . $row['functional_category_name_item'] . '（项）';

            if ($row['general_public_budget'] > 0) {
                if (isset($arr[$key])) {
                    $arr[$key]['total'] += $row['general_public_budget'];
                } else {
                    $arr[$key] = [
                        'title' => $title,
                        'total' => $row['general_public_budget']
                    ];
                }
            }
        }
        var_dump($arr);

        // 指令输出
        $output->writeln('app\command\gencode');
    }
}
